import { Injectable } from '@nestjs/common';
import * as ExcelJS from 'exceljs';
@Injectable()
export class ExcelService {
    async exportExcel(headers: string[], columns: string[], data: any[], imageKeys?: string[]): Promise<Buffer> {
        const workbook = new ExcelJS.Workbook();
        const worksheet = workbook.addWorksheet('Sheet1');

        // 添加表头
        worksheet.addRow(headers);

        // 添加数据
        data.forEach((item) => {
            const row = columns.map((column) => item[column]);
            worksheet.addRow(row);
        });

        // 处理图片
        // 你需要根据实际情况实现添加图片的逻辑

        const excelBuffer = await workbook.xlsx.writeBuffer() as Buffer;
        return excelBuffer;
    }
}